package collection.map;

import java.util.HashMap;

public class MapTest {
    public static void main(String[] args) {
        var staff = new HashMap<String,Employee>();
        staff.put("144-25-5464",new Employee("Amy Lee"));
        staff.put("567-24-2546",new Employee("Harry Hacker"));
        staff.put("157-62-7935",new Employee("Gary Cooper"));
        staff.put("456-62-5527",new Employee("Francesca Cruz"));
        //var b = staff.put("456-62-5527",new Employee("Francesca Cruz"));
        //System.out.println(b);//null

        //print all entries
        System.out.println(staff);

        //remove an entry
        staff.remove("567-24-2546");

        //replace an entry 如果这个键已存在，新的对象讲取代与这个键关联的就对象，并返回关联的旧值，如果键不存在，则返回null；
        //var a = staff.put("456-62-5527",new Employee("Francesca Miller"));//Employee{ename='Francesca Cruz'}
        //System.out.println(a);
        staff.put("456-62-5527",new Employee("Francesca Miller"));
        //look up a value
        System.out.println(staff.get("157-62-7935"));

        //iterate through all entries
        staff.forEach((k, v) ->
                System.out.println("key = "+ k + ",value = "+v));

        System.out.println(staff.containsKey("157-62-7935"));//true
    }

}
